package com.jneagle.xlstool.bzwgjmx.view.gui;

import javax.swing.table.AbstractTableModel;
import java.io.File;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
 * 文件表格模型。
 *
 * @author DwArFeng
 * @since 1.0.0
 */
class FileTableModel extends AbstractTableModel {

    private static final long serialVersionUID = -8573916733710426016L;

    private List<File> files = Collections.emptyList();

    @Override
    public int getRowCount() {
        return files.size();
    }

    @Override
    public int getColumnCount() {
        return 2;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        if (Objects.equals(columnIndex, 0)) {
            return rowIndex + 1;
        } else {
            return files.get(rowIndex).getAbsolutePath();
        }
    }

    @Override
    public String getColumnName(int column) {
        if (Objects.equals(column, 0)) {
            return "ui.label.035";
        } else {
            return "ui.label.036";
        }
    }

    public void updateData(List<File> files) {
        if (Objects.isNull(files)) {
            files = Collections.emptyList();
        }
        this.files = files;
        fireTableDataChanged();
    }
}
